﻿<cfsilent>
	<cfscript>
		
		sessionAdvice = getProperty("serviceFactory").getBean("sessionAdvice");
		dictAdvice = getProperty("serviceFactory").getBean("senateDictionaryAdvice");
		mathAdvice = getProperty("serviceFactory").getBean("senateMathAdvice");
		
		event.setArg("pageTitle", "网上成绩录入 - 成绩录入情况");
		
		termId = event.getArg("TID", event.getArg("TermID"));
		depId = sessionAdvice.getUserProp("teacherDepartment");
		
		academicYear = event.getArg("AcademicYear");
		academicTerm = event.getArg("AcademicTerm");
		
		targetArgs = structNew();
		structInsert(targetArgs, "TID", termId, true);
		structInsert(targetArgs, "DepID", depId, true);
		
		currentTab = event.getArg("TabID", "labTask");
		
		/* 任课单位信息 */
		sql = "SELECT
					i.institute_id,i.institute_name
				FROM
					t_institute i
				WHERE
					i.institute_id = :depID ";
		
		queryObj = new Query(datasource = application.dnsSlave);
		queryObj.addParam(name = "depID", value=depID, cfsqltype="cf_sql_varchar");
		rs_departmentEntity = queryObj.execute(sql = sql).getResult();

		/* 读取已激活成绩任务提交状况 */
		sql = "	SELECT
					tm.task_id,tm.task_type,tm.task_prog,tm.mark_done,tm.mark_need,
					c.course_name,c.course_credit,
					c.course_code,
					tm.cidx,
					i.institute_short,
					c.mark_mode
				FROM
					t_task_mark tm
					INNER JOIN t_course c ON c.cid = tm.cid
					INNER JOIN t_institute i ON i.institute_id = c.institute_id
				WHERE
					i.institute_id = :depId 
					AND
					tm.term_id = :termId 
				ORDER BY
					tm.task_prog DESC,
					c.course_name,tm.cidx";

		queryObj = new Query(datasource = application.dnsSlave);
		queryObj.addParam(name = "depId", value=depId, cfsqltype="cf_sql_varchar");
		queryObj.addParam(name = "termId", value=termId, cfsqltype="cf_sql_char");
		rs_task = queryObj.execute(sql = sql).getResult();
		
		/* 历史未提交成绩 */
		sql = "	SELECT
					tm.task_id,tm.task_type,tm.task_prog,tm.mark_done,tm.mark_need,
					c.course_name,c.course_credit,
					c.course_code,
					tm.cidx,
					i.institute_short,
					c.mark_mode
				FROM
					t_task_mark tm
					INNER JOIN t_course c ON tm.cid = c.cid
					INNER JOIN t_institute i ON c.institute_id = i.institute_id
				WHERE
					i.institute_id = :depId 
					AND
					tm.term_id < :termId 
					AND
					tm.task_prog in ('0','1','2','4')
				ORDER BY
					tm.task_prog DESC,c.course_name,tm.cidx";
		
		queryObj = new Query(datasource = application.dnsSlave);
		queryObj.addParam(name = "depId", value=depId, cfsqltype="cf_sql_varchar");
		queryObj.addParam(name = "termId", value=termId, cfsqltype="cf_sql_char");
		rs_taskUndone = queryObj.execute(sql = sql).getResult();

		sql = "	SELECT
					tsk.tsk_id,c.course_name,tch.tch_name,tsk.cidx,tsk.task_week,
					tsk.task_limite,tsk.task_chooesd,ct.cr_type_name,tc.campus_name,
					CASE WHEN tsk.task_time IS NULL THEN '-' ELSE tsk.task_time END task_time,
					CASE WHEN tsk.task_place IS NULL THEN '-' ELSE tsk.task_place END task_place,
					tsk.task_prop
				FROM
					t_task tsk
					INNER JOIN t_course c ON tsk.cid = c.cid
					INNER JOIN t_teacher tch ON tch.tch_id = tsk.tch_id
					INNER JOIN t_classroom_type ct ON tsk.cr_type = ct.cr_type
					INNER JOIN t_campus tc ON tsk.campus_id = tc.campus_id
				WHERE
					tsk.term_id = :termId 
					AND
					c.institute_id = :depId 
					AND NOT EXISTS(
						SELECT 0 FROM t_task_mark tm WHERE tm.task_id = tsk.tsk_id AND tm.term_id = :termId 
					)
					AND
					SUBSTR(tsk.task_prop,7,1)='0'
				ORDER BY
					c.course_name,tsk.cidx";

		queryObj = new Query(datasource = application.dnsSlave);
		queryObj.addParam(name = "depId", value=depId, cfsqltype="cf_sql_varchar");
		queryObj.addParam(name = "termId", value=termId, cfsqltype="cf_sql_char");
		rs_planTask = queryObj.execute(sql = sql).getResult();

		sql = "	SELECT
					tsk.tsk_id,c.course_name,tch.tch_name,tsk.cidx,tsk.task_week,
					tsk.task_limite,tsk.task_chooesd,ct.cr_type_name,tc.campus_name,
					CASE WHEN tsk.task_time IS NULL THEN '-' ELSE tsk.task_time END task_time,
					CASE WHEN tsk.task_place IS NULL THEN '-' ELSE tsk.task_place END task_place,
					tsk.task_prop
				FROM
					t_common_task tsk
					INNER JOIN t_course c ON tsk.cid = c.cid
					INNER JOIN t_teacher tch ON tch.tch_id = tsk.tch_id
					INNER JOIN t_classroom_type ct ON tsk.cr_type = ct.cr_type
					INNER JOIN t_campus tc ON tsk.campus_id = tc.campus_id
				WHERE
					tsk.term_id = :termId 
					AND
					c.institute_id = :depId 
					AND NOT EXISTS(
						SELECT 0 FROM t_task_mark tm WHERE tm.task_id = tsk.tsk_id AND tm.term_id = :termId 
					)
					AND
					SUBSTR(tsk.task_prop,7,1)='0'
				ORDER BY
					c.course_name,tsk.cidx";

		queryObj = new Query(datasource = application.dnsSlave);
		queryObj.addParam(name = "depId", value=depId, cfsqltype="cf_sql_varchar");
		queryObj.addParam(name = "termId", value=termId, cfsqltype="cf_sql_char");
		rs_commonTask = queryObj.execute(sql = sql).getResult();

		if( rs_task.recordCount eq 0 AND (rs_planTask.recordCount OR rs_commonTask.recordCount)){
			currentTab = "labTaskWait";
		}
		
	</cfscript>
</cfsilent>

<div id="headArea">
	<div class="uiHeader uiHeaderWithImage ptm">
		<div class="clearfix uiHeaderTop">
			<div class="uiHeaderActions rfloat">
				<a class="uiButton" href="<cfoutput>#buildURL('DEFAULT_EVENT')#</cfoutput>"><i class="mrs img btnPublish"></i><span class="uiButtonText">教学运行安排</span></a>
			</div>
			<div>
				<h2 class="uiHeaderTitle">
					<i class="uiHeaderImage img icon16x16 application"></i><cfoutput>#academicYear#</cfoutput>-<cfoutput>#academicTerm#</cfoutput>学期成绩提交情况
				</h2>
			</div>
		</div>
	</div>
</div>

<div class="UIElement">
	<ul class="senateFirstPage">
		<li>
			<div class="clearfix" id="summary">
			
				<div class="UItab">
					<div class="tabLables">
						<cfif rs_task.recordCount>
							<span <cfif currentTab eq "labTask">class="active"</cfif> id="labTask" tabTarget="Task">成绩提交状态</span>
						</cfif>
						<cfif rs_taskUndone.recordCount>
							<span <cfif currentTab eq "labHistory">class="active"</cfif> id="labHistory" tabTarget="History">以往学期未提交成绩</span>
						</cfif>
						<cfif rs_planTask.recordCount or rs_commonTask.recordCount>
							<span <cfif currentTab eq "labTaskWait">class="active"</cfif> id="labTaskWait" tabTarget="TaskWait">尚未开始录入</span>
						</cfif>
					</div>
				</div>
			
				<script language="javascript" type="text/javascript">
					//<![CDATA[
					<!--
					$(document).ready(function() {
						
						/* init Tab */
						$("div.tabContent").hide();
						$("div#" + $("div.tabLables span.active").attr("tabTarget")).show();
				
						$("div.tabLables > span").click(function(){
							var $targetID = $(this).attr("tabTarget");
							
							$("div.tabLables span").removeClass("active");
							$(this).addClass("active");
							
							$("div.tabContent").not('[id="' + $targetID + '"]').hide();
							$("div.tabContent#" + $targetID).show();
						});
				
					});
					// -->
					//]]>
				</script>
				
				<cfif rs_task.recordCount>

					<div id="Task" class="tabContent">
					
						<cfif rs_departmentEntity.recordCount>
							<cfset structInsert(targetArgs, "DepID", rs_departmentEntity.institute_id, true) />
							<div class="noticeBlock">
								<h3><cfoutput>#rs_departmentEntity.institute_name#</cfoutput></h3>
								<p>
									<span class="img icon16x16 message"></span>
									<em><cfoutput>#academicYear#</cfoutput>-<cfoutput>#academicTerm#</cfoutput></em>学期, 
									已网上成绩录入课程教学任务 <em><cfoutput>#rs_task.recordCount#</cfoutput></em> 个
									.
								</p>
								<hr/>
							</div>
						</cfif>

						<table class="UIEditable">
							<thead>
								<tr>
									<td width="30"></td>
									<td>课程</td>
									<td width="90">主讲教师</td>
									<td width="40">学分</td>
									<td width="50">部门</td>
									<td width="60">提交进度</td>
									<td width="60">计分模式</td>
									<td width="60">状态</td>
									<td width="18"></td>
								</tr>
							</thead>
							<tbody>
								<cfset row = 0 />
                                <cfloop query="rs_task">
									<cfset row++ />
									<cfset structInsert(targetArgs, "TSK", rs_task.task_id, true) />
									<cfset structInsert(targetArgs, "TT", rs_task.task_type, true) />
									<!--- 反向读取任务的主讲教师 --->
                                    <cfswitch expression="#rs_task.task_type#">
                                    	<cfcase value="P">
											<cfscript>
                                            	sql = "	SELECT
															tch.tch_name
														FROM
															t_task tsk
															INNER JOIN t_teacher tch ON tch.tch_id = tsk.tch_id
														WHERE
															tsk.tsk_id = :taskId ";
	
												queryObj = new Query(datasource = application.dnsSlave);
												queryObj.addParam(name = "taskId", value=rs_task.task_id, cfsqltype="cf_sql_varchar");
												rs_targetTaskEntity = queryObj.execute(sql = sql).getResult();

                                            </cfscript>
                                        </cfcase>
                                        <cfcase value="C">
											<cfscript>
                                            	sql = "	SELECT
															tch.tch_name
														FROM
															t_common_task tsk
															INNER JOIN t_teacher tch ON tch.tch_id = tsk.tch_id
														WHERE
															tsk.tsk_id = :taskId ";
	
												queryObj = new Query(datasource = application.dnsSlave);
												queryObj.addParam(name = "taskId", value=rs_task.task_id, cfsqltype="cf_sql_varchar");
												rs_targetTaskEntity = queryObj.execute(sql = sql).getResult();

                                            </cfscript>
                                        </cfcase>
                                        <cfcase value="R">
											<cfscript>
                                            	sql = "	SELECT
															tch.tch_name
														FROM
															t_reopen_task tsk
															INNER JOIN t_teacher tch ON tch.tch_id = tsk.tch_id
														WHERE
															tsk.tsk_id = :taskId ";
	
												queryObj = new Query(datasource = application.dnsSlave);
												queryObj.addParam(name = "taskId", value=rs_task.task_id, cfsqltype="cf_sql_varchar");
												rs_targetTaskEntity = queryObj.execute(sql = sql).getResult();

                                            </cfscript>
                                        </cfcase>
                                        <cfcase value="T">
											<cfscript>
                                            	sql = "	SELECT
															tch.tch_name
														FROM
															t_sport_task tsk
															INNER JOIN t_teacher tch ON tch.tch_id = tsk.tch_id
														WHERE
															tsk.tsk_id = :taskId ";
	
												queryObj = new Query(datasource = application.dnsSlave);
												queryObj.addParam(name = "taskId", value=rs_task.task_id, cfsqltype="cf_sql_varchar");
												rs_targetTaskEntity = queryObj.execute(sql = sql).getResult();

                                            </cfscript>
                                        </cfcase>
                                    </cfswitch>
									<tr class="editRows" rowid="<cfoutput>#rs_task.task_id#</cfoutput>">
										<td class="index"><cfoutput>#row#</cfoutput></td>
										<td><cfoutput>#rs_task.course_name#</cfoutput><span class="numeric">-<cfoutput>#rs_task.cidx#</cfoutput></span></td>
										<td><cfoutput>#rs_targetTaskEntity.tch_name#</cfoutput></td>
										<td><span class="numeric"><cfoutput>#numberFormat(rs_task.course_credit, '_.__')#</cfoutput></span></td>
										<td><cfoutput>#rs_task.institute_short#</cfoutput></td>
										<td align="center"><span class="numeric"><cfoutput>#rs_task.mark_done#</cfoutput> / <cfoutput>#rs_task.mark_need#</cfoutput></span></td>
										<td align="center"><cfoutput>#dictAdvice.getMarkModeName( rs_task.mark_mode )#</cfoutput></td>
										<td class="TaskProgress<cfoutput>#rs_task.task_prog#</cfoutput>"><cfoutput>#dictAdvice.getTaskMarkStat( rs_task.task_prog )#</cfoutput></td>
										<td>
											<cfif rs_task.task_prog eq "3">
												<a target="_blank" title="打印成绩单" href="<cfoutput>#buildURL('taskMarkPrint', targetArgs)#</cfoutput>" class="stat print"></a>
											</cfif>
										</td>
									</tr>
								</cfloop>
							</tbody>
						</table>
					</div>
					
				</cfif>

				<cfif rs_taskUndone.recordCount>

					<div id="History" class="tabContent">
					
						<cfif rs_departmentEntity.recordCount>
							<cfset structInsert(targetArgs, "DepID", rs_departmentEntity.institute_id, true) />
							<div class="noticeBlock">
								<h3><cfoutput>#rs_departmentEntity.institute_name#</cfoutput></h3>
								<p>
									<span class="img icon16x16 message"></span>
									以往学期尚未完成成绩提交的教学任务 <em><cfoutput>#rs_taskUndone.recordCount#</cfoutput></em> 个.
								</p>
								<hr/>
							</div>
						</cfif>

						<table class="UIEditable">
							<thead>
								<tr>
									<td width="30"></td>
									<td>课程</td>
									<td width="90">主讲教师</td>
									<td width="40">学分</td>
									<td width="50">部门</td>
									<td width="60">提交进度</td>
									<td width="60">计分模式</td>
									<td width="60">状态</td>
								</tr>
							</thead>
							<tbody>
								<cfset row = 0 />
                                <cfloop query="rs_taskUndone">
									<cfset row++ />
									<!--- 反向读取任务的主讲教师 --->
                                    <cfswitch expression="#rs_taskUndone.task_type#">
                                    	<cfcase value="P">
											<cfscript>
                                            	sql = "	SELECT
															tch.tch_name
														FROM
															t_task tsk
															INNER JOIN t_teacher tch ON tch.tch_id = tsk.tch_id
														WHERE
															tsk.tsk_id = :taskId ";
	
												queryObj = new Query(datasource = application.dnsSlave);
												queryObj.addParam(name = "taskId", value=rs_taskUndone.task_id, cfsqltype="cf_sql_varchar");
												rs_targetTaskEntity = queryObj.execute(sql = sql).getResult();
                                            </cfscript>
                                        </cfcase>
                                        <cfcase value="C">
											<cfscript>
                                            	sql = "	SELECT
															tch.tch_name
														FROM
															t_common_task tsk
															INNER JOIN t_teacher tch ON tch.tch_id = tsk.tch_id
														WHERE
															tsk.tsk_id = :taskId ";
	
												queryObj = new Query(datasource = application.dnsSlave);
												queryObj.addParam(name = "taskId", value=rs_taskUndone.task_id, cfsqltype="cf_sql_varchar");
												rs_targetTaskEntity = queryObj.execute(sql = sql).getResult();
                                            </cfscript>
                                        </cfcase>
                                        <cfcase value="R">
											<cfscript>
                                            	sql = "	SELECT
															tch.tch_name
														FROM
															t_reopen_task tsk
															INNER JOIN t_teacher tch ON tch.tch_id = tsk.tch_id
														WHERE
															tsk.tsk_id = :taskId ";
	
												queryObj = new Query(datasource = application.dnsSlave);
												queryObj.addParam(name = "taskId", value=rs_taskUndone.task_id, cfsqltype="cf_sql_varchar");
												rs_targetTaskEntity = queryObj.execute(sql = sql).getResult();
                                            </cfscript>
                                        </cfcase>
                                        <cfcase value="T">
											<cfscript>
                                            	sql = "	SELECT
															tch.tch_name
														FROM
															t_sport_task tsk
															INNER JOIN t_teacher tch ON tch.tch_id = tsk.tch_id
														WHERE
															tsk.tsk_id = :taskId ";
	
												queryObj = new Query(datasource = application.dnsSlave);
												queryObj.addParam(name = "taskId", value=rs_taskUndone.task_id, cfsqltype="cf_sql_varchar");
												rs_targetTaskEntity = queryObj.execute(sql = sql).getResult();
                                            </cfscript>
                                        </cfcase>
                                    </cfswitch>

									<tr class="editRows" rowid="<cfoutput>#rs_taskUndone.task_id#</cfoutput>">
										<td class="index"><cfoutput>#row#</cfoutput></td>
										<td><cfoutput>#rs_taskUndone.course_name#</cfoutput><span class="numeric">-<cfoutput>#rs_taskUndone.cidx#</cfoutput></span></td>
										<td><cfoutput>#rs_targetTaskEntity.tch_name#</cfoutput></td>
										<td><span class="numeric"><cfoutput>#numberFormat(rs_taskUndone.course_credit, '_.__')#</cfoutput></span></td>
										<td><cfoutput>#rs_taskUndone.institute_short#</cfoutput></td>
										<td align="center"><span class="numeric"><cfoutput>#rs_taskUndone.mark_done#</cfoutput> / <cfoutput>#rs_taskUndone.mark_need#</cfoutput></span></td>
										<td align="center"><cfoutput>#dictAdvice.getMarkModeName( rs_taskUndone.mark_mode )#</cfoutput></td>
										<td class="TaskProgress<cfoutput>#rs_taskUndone.task_prog#</cfoutput>"><cfoutput>#dictAdvice.getTaskMarkStat( rs_taskUndone.task_prog )#</cfoutput></td>
									</tr>
								</cfloop>
							</tbody>
						</table>
					
					</div>
				</cfif>

				<div id="TaskWait" class="tabContent">
					
					<cfif rs_departmentEntity.recordCount>
							
						<cfset structInsert(targetArgs, "DepID", rs_departmentEntity.institute_id, true) />
							
						<div class="noticeBlock">
							<h3><cfoutput>#rs_departmentEntity.institute_name#</cfoutput></h3>
							<p>
								<span class="img icon16x16 message"></span>
								<em><cfoutput>#academicYear#</cfoutput>-<cfoutput>#academicTerm#</cfoutput></em>学期, 
								需承担计划课程教学任务 <em><cfoutput>#rs_planTask.recordCount#</cfoutput></em> 个,
								需承担全通通选课程教学任务 <em><cfoutput>#rs_commonTask.recordCount#</cfoutput></em> 个
								.
							</p>
							<hr/>
						</div>
						
					</cfif>
					
					<cfif rs_planTask.recordCount or rs_commonTask.recordCount>

							<table id="classList" class="UIEditable">
								<thead>
									<tr>
										<td width="30"></td>
										<td>教学班</td>
										<td width="90">主讲教师</td>
										<td>周次</td>
										<td>人数</td>
										<td>校区</td>
										<td>教室类别</td>
										<td>上课时间</td>
										<td>上课地点</td>
									</tr>
								</thead>
								<tbody>
									<cfset row = 0 />
                                    <cfloop query="rs_planTask">
										<cfset row++ />
										<tr class="editRows" rowid="<cfoutput>#rs_planTask.tsk_id#</cfoutput>">
											<td class="index">P.<cfoutput>#row#</cfoutput></td>
											<td><cfoutput>#rs_planTask.course_name#</cfoutput><span class="numeric">-<cfoutput>#rs_planTask.cidx#</cfoutput></span></td>
											<td><cfoutput>#rs_planTask.tch_name#</cfoutput></td>
											<td><span class="numeric"><cfoutput>#rs_planTask.task_week#</cfoutput></span></td>
											<td><span class="numeric"><cfoutput>#rs_planTask.task_chooesd#</cfoutput></span></td>
											<td><cfoutput>#rs_planTask.campus_name#</cfoutput></td>
											<td><cfoutput>#rs_planTask.cr_type_name#</cfoutput></td>
											<td><cfoutput>#replace(mathAdvice.convertTaskTime(rs_planTask.task_time), ",", "<br/>", "all")#</cfoutput></td>
											<td><cfoutput>#replace(rs_planTask.task_place, ",", "<br/>", "all")#</cfoutput></td>
										</tr>
									</cfloop>
									
									<cfset row = 0 />
                                    <cfloop query="rs_commonTask">
										<cfset row++ />
										<tr class="editRows" rowid="<cfoutput>#rs_commonTask.tsk_id#</cfoutput>">
											<td class="index">C.<cfoutput>#row#</cfoutput></td>
											<td><cfoutput>#rs_commonTask.course_name#</cfoutput><span class="numeric">-<cfoutput>#rs_commonTask.cidx#</cfoutput></span></td>
											<td><cfoutput>#rs_commonTask.tch_name#</cfoutput></td>
											<td><span class="numeric"><cfoutput>#rs_commonTask.task_week#</cfoutput></span></td>
											<td><span class="numeric"><cfoutput>#rs_commonTask.task_chooesd#</cfoutput></span></td>
											<td><cfoutput>#rs_commonTask.campus_name#</cfoutput></td>
											<td><cfoutput>#rs_commonTask.cr_type_name#</cfoutput></td>
											<td><cfoutput>#replace(mathAdvice.convertTaskTime(rs_commonTask.task_time), ",", "<br/>", "all")#</cfoutput></td>
											<td><cfoutput>#replace(rs_commonTask.task_place, ",", "<br/>", "all")#</cfoutput></td>
										</tr>
									</cfloop>
								</tbody>
							</table>
							
							
						</cfif>
					
				</div>
				
			</div>
		</li>
	</ul>
</div>
			
			
